<!DOCTYPE html>
<html lang="zh">

<head>
  <meta charset="UTF-8" />
  <title>新建文章</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
  <link rel="stylesheet" href="/app/laoha/sdk/sdk.css" />
  <link rel="stylesheet" href="/app/laoha/sdk/helper.css" />
  <link rel="stylesheet" href="/app/laoha/sdk/iconfont.css" />
  <style>
    html,
    body,
    .app-wrapper {
      position: relative;
      width: 100%;
      height: 100%;
      margin: 0;
      padding: 0;
    }

    img {
			max-width: 100%;
		}
  </style>
</head>

<body>
  <div id="root" class="app-wrapper"></div>
  <script src="/app/laoha/sdk/sdk.js"></script>
  <script type="text/javascript">
    // API相关常量const 
    const GROUP_API = "/app/laoha/admin/post/groups";
    const CREATE_API = "post:/app/laoha/admin/post/store";
    const UPLOAD_IMAGE = "post:/app/admin/upload/insert";
    const UPLOAD_FILE = "post:/app/admin/upload/insert";
    (function () {
      let amis = amisRequire('amis/embed');
      // 通过替换下面这个配置来生成不同页面
      let amisJSON = {
        "type": "page",
        "data":<?= json_encode($params, JSON_UNESCAPED_UNICODE) ?>,
        "body": {
          "type": "form",
          "title": "新建文章",
          "redirect": "/app/laoha/admin/post?order_by=-id",
          "mode": "normal",
          "api": CREATE_API,
          "body": [        
            {
              "type": "hidden",
              "name": "status",
              "value": "${config.check?'1':'0'}",
            },   
            {
              "type": "hidden",
              "name": "root",
              "value": "post",
            },
            {
              "type": "input-text",
              "name": "title",
              "placeholder": "请输入标题",
              "required": true
            },
            {
              "type": "input-rich-text",
              "name": "content",
              "label": "",
              "receiver": UPLOAD_IMAGE,
              "required": true,
              "options": {
                "convert_urls": false,
                "image_dimensions": false,
                "content_style":"img {max-width:100%}"  //编辑器内图片最大宽度
              }
            },
            {
              "type": "group",
              "body": [
                {
                  "type": "tree-select",
                  "name": "cate_id",
                  "label": "选择分类",
                  "onlyLeaf": true,
                  "hideNodePathLabel": true,
                  "labelField": "title",
                  "valueField": "id",
                  "source": "${cates}",
                  "required": true
                },
                {
                  "type": "select",
                  "name": "group",
                  "label": "选择分组",
                  "source": GROUP_API+"?id=${cate_id}",
                  "visibleOn": "${config.groups}"
                }
              ]
            },
            {
              "type": "input-image",
              "name": "images",
              "label": "图片附件(可多选)",
              "accept": ".jpeg,.jpg,.png,.gif",
              "draggable":true,
              "multiple":true,
              "maxLength":20,    //一次最多上传20个
              "maxSize": 20960000,
              "receiver": UPLOAD_IMAGE,
            },
            {
              "type": "group",
              "body": [
                {
                  "type": "input-file",
                  "name": "attaches",
                  "multiple": true,
                  "label": "其它附件(可多选)",
                  "maxSize": 209600000,
                  "maxLength":20,
                  "receiver": UPLOAD_FILE,
                }
              ]
            }
          ],
          "actions": [
            {
              "type": "submit",
              "level": "primary",
              "label": "确定"
            },
            {
              "type": "button",
              "label": "返回",
              "level": "default",
              "onEvent": {
                "click": {
                  "actions": [
                    {
                      "actionType": "goBack"
                    }
                  ]
                }
              }
            }
          ]
        }
      };
      let amisScoped = amis.embed('#root', amisJSON, {}, { toastPosition: 'center' });
    })();
  </script>
</body>

</html>